home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / pmake / lst / RCS / lstForEachFrom.c,v < prev    next >
Encoding:
Text File  |  1992-05-19  |  2.4 KB  |  112 lines

  1. head     1.8;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.8
  10. date     89.07.13.13.55.55;  author adam;  state Exp;
  11. branches ;
  12. next     ;
  13.  
  14.  
  15. desc
  16. @@
  17.  
  18.  
  19.  
  20. 1.8
  21. log
  22. @checked in with -k by kupfer at 92.05.18.17.32.39.
  23. @
  24. text
  25. @/*-
  26.  * lstForEachFrom.c --
  27.  *    Perform a given function on all elements of a list starting from
  28.  *    a given point.
  29.  *
  30.  * Copyright (c) 1988 by University of California Regents
  31.  *
  32.  * Permission to use, copy, modify, and distribute this
  33.  * software and its documentation for any purpose and without
  34.  * fee is hereby granted, provided that the above copyright
  35.  * notice appears in all copies.  Neither the University of California nor
  36.  * Adam de Boor makes any representations about the suitability of this
  37.  * software for any purpose.  It is provided "as is" without
  38.  * express or implied warranty.
  39.  */
  40. #ifndef lint
  41. static char *rcsid =
  42. "$Id: lstForEachFrom.c,v 1.8 89/07/13 13:55:55 adam Exp $ SPRITE (Berkeley)";
  43. #endif lint
  44.  
  45. #include    "lstInt.h"
  46.  
  47. /*-
  48.  *-----------------------------------------------------------------------
  49.  * Lst_ForEachFrom --
  50.  *    Apply the given function to each element of the given list. The
  51.  *    function should return 0 if traversal should continue and non-
  52.  *    zero if it should abort. 
  53.  *
  54.  * Results:
  55.  *    None.
  56.  *
  57.  * Side Effects:
  58.  *    Only those created by the passed-in function.
  59.  *
  60.  *-----------------------------------------------------------------------
  61.  */
  62. /*VARARGS2*/
  63. void
  64. Lst_ForEachFrom (l, ln, proc, d)
  65.     Lst                    l;
  66.     LstNode              ln;
  67.     register int    (*proc)();
  68.     register ClientData    d;
  69. {
  70.     register ListNode    tln = (ListNode)ln;
  71.     register List     list = (List)l;
  72.     register ListNode    next;
  73.     Boolean             done;
  74.     int                 result;
  75.     
  76.     if (!LstValid (list) || LstIsEmpty (list)) {
  77.     return;
  78.     }
  79.     
  80.     do {
  81.     /*
  82.      * Take care of having the current element deleted out from under
  83.      * us.
  84.      */
  85.     
  86.     next = tln->nextPtr;
  87.     
  88.     tln->useCount++;
  89.     result = (*proc) (tln->datum, d);
  90.     tln->useCount--;
  91.  
  92.     /*
  93.      * We're done with the traversal if
  94.      *  - nothing's been added after the current node and
  95.      *  - the next node to examine is the first in the queue or
  96.      *    doesn't exist.
  97.      */
  98.     done = (next == tln->nextPtr &&
  99.         (next == NilListNode || next == list->firstPtr));
  100.     
  101.     next = tln->nextPtr;
  102.  
  103.     if (tln->flags & LN_DELETED) {
  104.         free((char *)tln);
  105.     }
  106.     tln = next;
  107.     } while (!result && !LstIsEmpty(list) && !done);
  108.     
  109. }
  110.  
  111. @
  112.